<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsuariosRolesTable extends Migration {

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('usuarios_roles', function(Blueprint $table)
		{
			$table->integer('user_id')->unsigned();
			$table->integer('rol_id')->unsigned();
			
			$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
			$table->foreign('rol_id')->references('id')->on('roles')->onDelete('cascade');
			
			$table->primary(array('user_id','rol_id'));
			
			$table->timestamps();
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::table('usuarios_roles', function(Blueprint $table)
		{
			$table->dropForeign('usuarios_roles_user_id_foreign');
			$table->dropForeign('usuarios_roles_rol_id_foreign');
		});
		
		Schema::dropIfExists('usuarios_roles');
	}

}
